package myjava.processi;

public class Root1 {

   public static void main(String[] args) {

      Thread t1 = new Laurent("Laurent");
      Thread t2 = new Fabs();
      Thread t3 = new Thread(new Luigi(), "T3");

      // L'ordine dei messaggi printati non e' garantito!
      // i thread sono processi paralleli gestiti dal sistema operativo e l'OS
      // fa appunto quel cazzo che vuole e li gestisce come vuole in termini di esecuzione nel tempo

      // these 3 will sleep for 10 secs
      t1.start();
      t2.start();
      t3.start();
      
      int numActive = Thread.activeCount();
      System.out.println("num active threads : " + numActive);
   }
}

class Laurent extends Thread {

   public Laurent() {
      super();
   }

   public Laurent(String n) {
      super(n);
   }

   @Override
   public void run() {
      super.run();
      System.out.println("hello I am " + this.getName() + " and I am going to sleep!");
      try {
         Thread.sleep(5000);
      } catch (Exception e) {
         
      }
   }
}

class Fabs extends Thread {

   public Fabs() {
      super();
   }

   public Fabs(String n) {
      super(n);
   }

   @Override
   public void run() {
      super.run();
      System.out.println("hello I am " + this.getName() + " and I am going to sleep too!");
      try {
         Thread.sleep(5000);
      } catch (Exception e) {
         
      }
   }
}

class Luigi implements Runnable {

   public void run() {
      String n = Thread.currentThread().getName();
      System.out.println("hello I am an implementation of Runnable (Luigi is my name!) and I am running in the Thread named: " + n);
      try {
         Thread.sleep(5000);
      } catch (Exception e) {

      }
   }
}